/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.cheln.explorer.beans;

import android.content.Context;
import cn.cheln.explorer.func.AppSrc;

/**
 *
 * @author chenliang
 */
public class ApkInfoUtil {
    public static boolean bindFlag;
    public static <T extends FileInfo> boolean preserApkInfo(FileInfo fileInfo, Context context) {
        ApkInfo apkInfo = (ApkInfo) fileInfo;
        if (!apkInfo.isBuilt) {
            if (!apkInfo.setApkInfo(context)) {
                apkInfo.versionCondition = ApkInfo.DISPLAY_UNKNOWN;
                apkInfo.versionName = ApkInfo.DISPLAY_UNKNOWN;
                return true;
            }
            String anotherVersionName = AppSrc.getPackagesVersion().get(apkInfo.packageName);
            int result;
            if (anotherVersionName != null) {
//                Logs.i("--- apk compare " + apkInfo.name + " " + apkInfo.versionName + " " + anotherVersionName);
//                result = new ApkInfo.ApkVersionName(apkInfo.versionName).compareTo(new ApkInfo.ApkVersionName(anotherVersionName));
//                if (result > 0) {
//                    apkInfo.versionCondition = ApkInfo.VERSION_UPGRADE;
//                } else if (result < 0) {
                    apkInfo.versionCondition = ApkInfo.VERSION_INTALLED;
//                } else if (result == 0) {
//                    apkInfo.versionCondition = ApkInfo.VERSION_UPDATETODATE;
//                }
            } else {
                apkInfo.versionCondition = ApkInfo.VERSION_UNINTALLED;
            }
        }
        return false;
    }

}
